/*-----------------------------------------------File Info------------------------------------------------
** File Name:               pwm user.c  
** Last modified date:      2022.06.12
** Last version:            V0.1
** Description:             
**--------------------------------------------------------------------------------------------------------            
** Created date:            2022.06.12
** author:                  YLY
** Version:                 V0.1
** Descriptions:            pwm驱动
** 驱动参考:https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-standard/programming-manual/device/pwm/pwm
**--------------------------------------------------------------------------------------------------------
*/

#ifndef _PWM_H_
#define	_PWM_H_

#include "bspConfig.h"
#include "bspGPIO.h"

typedef struct 
{
	rcu_periph_enum timerRcu;
	uint32_t timerPeriph;
	uint32_t channel;
	
	tsCfgGpio gpio;
}tsPwm;

#define DEV_PWM0 	/*PA8,	TIMER0_CH0,	AF2	PWM0*/\
		{RCU_TIMER0, TIMER0, TIMER_CH_0, RCU_GPIOA, GPIOA, GPIO_PIN_8, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_2, 0}		
				
#define DEV_PWM1 	/*PA9,	TIMER0_CH1,	AF2 PWM1*/\
		{RCU_TIMER0, TIMER0, TIMER_CH_1, RCU_GPIOA, GPIOA, GPIO_PIN_9, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_2, 0}
		
#define DEV_PWM2	/*PA10,	TIMER0_CH2,	AF2 PWM2*/ \
		{RCU_TIMER0, TIMER0, TIMER_CH_2, RCU_GPIOA, GPIOA, GPIO_PIN_10, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_2, 0}
		
#define DEV_PWM3	/*PA11,	TIMER0_CH3,	AF2 PWM3*/ \
		{RCU_TIMER0, TIMER0, TIMER_CH_3, RCU_GPIOA, GPIOA, GPIO_PIN_11, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_2, 0}	

#define DEV_PWM4	/*PB4,	TIMER2_CH0,	AF1 PWM4*/ \
		{RCU_TIMER2, TIMER2, TIMER_CH_0, RCU_GPIOB, GPIOB, GPIO_PIN_4, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_1, 0}	

#define DEV_PWM5	/*PB5,	TIMER2_CH1,	AF1 PWM5*/\
		{RCU_TIMER2, TIMER2, TIMER_CH_1, RCU_GPIOB, GPIOB, GPIO_PIN_5, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_1, 0}

#define DEV_PWM6	/*PB0,	TIMER2_CH2,	AF1 PWM6*/ \
		{RCU_TIMER2, TIMER2, TIMER_CH_2, RCU_GPIOB, GPIOB, GPIO_PIN_0, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_1, 0}		

#define DEV_PWM7	/*PB1,	TIMER2_CH3,	AF1 PWM7*/ \
		{RCU_TIMER2, TIMER2, TIMER_CH_3, RCU_GPIOB, GPIOB, GPIO_PIN_1, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_1, 0}			

#define DEV_PWM8	/*PA4,	TIMER13_CH0,AF4 PWM8*/ \
		{RCU_TIMER13, TIMER13, TIMER_CH_0, RCU_GPIOA, GPIOA, GPIO_PIN_4, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_4, 0}		

#define DEV_PWM9	/*PA7,	TIMER13_CH0,AF4 PWM9*/ \
		{RCU_TIMER13, TIMER13, TIMER_CH_1, RCU_GPIOA, GPIOA, GPIO_PIN_7, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_4, 0}		

#define DEV_PWM10	/*PA2,	TIMER14_CH0,AF0 PWM10*/ \
		{RCU_TIMER14, TIMER14, TIMER_CH_0, RCU_GPIOA, GPIOA, GPIO_PIN_2, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_0, 0}		

#define DEV_PWM11	/*PA3,	TIMER14_CH1,AF0 PWM11*/ \
		{RCU_TIMER14, TIMER14, TIMER_CH_1, RCU_GPIOA, GPIOA, GPIO_PIN_3, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_0, 0}		

#define DEV_PWM12	/*PA6,	TIMER15_CH0,AF5 PWM12*/ \
		{RCU_TIMER15, TIMER15, TIMER_CH_0, RCU_GPIOA, GPIOA, GPIO_PIN_6, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_2, 0}		

#define DEV_PWM14	/*PA7,	TIMER16_CH0,AF5 PWM13*/ \
		{RCU_TIMER16, TIMER16, TIMER_CH_0, RCU_GPIOA, GPIOA, GPIO_PIN_7, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_2, 0}	
		
#define DEV_PWM15	/*PA7,	TIMER16_CH0,AF5 PWM13*/ \
		{RCU_TIMER15, TIMER15, TIMER_CH_0, RCU_GPIOB, GPIOB, GPIO_PIN_8, \
		GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_AF_2, 0}	
		
/*PB13,	TIMER0_CH0,		AF2*/
/*PA6,	TIMER2_CH0,		AF1*/
/*PA7,	TIMER2_CH1,		AF0*/
/*PB1,	TIMER13_CH0,	AF0*/
/*PB14,	TIMER14_CH0,	AF1*/
/*PB15,	TIMER14_CH1,	AF1*/
/*PB8,	TIMER15_CH0,	AF2*/
/*PB9,	TIMER16_CH0,	AF2*/
/*PA1,	TIMER14_CH0_ON,	AF5*/
/*PA7,	TIMER0_CH0_ON,	AF2*/
/*PB0,	TIMER0_CH1_ON,	AF2*/
/*PB1,	TIMER0_CH2_ON,	AF2*/
/*PB6,	TIMER15_CH0_ON,	AF2*/
/*PB7,	TIMER16_CH0_ON,	AF2*/
/*PB14,	TIMER0_CH1_ON,	AF2*/
/*PB15,	TIMER0_CH2_ON,	AF2*/
/*PB15,	TIMER14_CH0_ON,	AF3*/

extern int8_t pwmInit(tsPwm *pwm, uint32_t freq, float duty);
extern int8_t pwmSet(tsPwm *pwm, uint32_t freq, float duty);
extern int8_t pwmEnable(tsPwm *pwm);
extern int8_t pwmDisable(tsPwm *pwm);
#endif




